<?php
// 通过php获取所有学生的信息；
$link = mysqli_connect("localhost","root","root","2116");
$sort = $_GET['sort'];
if($sort==1){
	// 获取数据库里的内容
	$sql = "SELECT * FROM students ORDER BY age DESC";
}else{
	// 获取数据库里的内容
	$sql = "SELECT * FROM students ORDER BY id";
}


$res  = mysqli_query($link,$sql);
// $one = mysqli_fetch_object($res);
// print_r($one);
// die;
$arr = [];
while($one=mysqli_fetch_assoc($res)){
	$arr[] = $one;
}

// print_r($arr);
echo json_encode($arr);

?>